#pragma once

#include "Instruction.h"
#include "LabelInstruction.h"

/// @brief 条件跳转指令类
class CondGotoInstruction : public Instruction {
private:
    Value *condition;                 // 条件值
    LabelInstruction *trueTarget;     // 条件为真时跳转目标
    LabelInstruction *falseTarget;    // 条件为假时跳转目标

public:
    /// @brief 构造函数
    /// @param func 所属函数
    /// @param cond 条件值
    /// @param trueLabel 真目标
    /// @param falseLabel 假目标
    CondGotoInstruction(Function *func, 
                       Value *cond, 
                       LabelInstruction *trueLabel,
                       LabelInstruction *falseLabel);

    /// @brief 转换为IR文本格式
    void toString(std::string &str) override;

    /// @brief 获取条件值
    Value *getCondition() const { return condition; }

    /// @brief 获取真目标标签
    LabelInstruction *getTrueLabel() const { return trueTarget; }

    /// @brief 获取假目标标签
    LabelInstruction *getFalseLabel() const { return falseTarget; }

    /// @brief 设置真目标标签
    void setTrueLabel(LabelInstruction *label) { trueTarget = label; }

    /// @brief 设置假目标标签
    void setFalseLabel(LabelInstruction *label) { falseTarget = label; }
};
